package my.assistant.homecashmanager.tally.domain;

import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import my.assistant.homecashmanager.tally.dao.TallyDao;
import my.assistant.homecashmanager.tally.data.JournalAccount;

import org.assistant.common.exception.GetFromDBException;
import org.assistant.common.exception.ImplementNotFoundException;
import org.assistant.common.exception.SaveIntoDBException;
import org.assistant.common.utils.ClassUtils;

public class TallyDomainImpl implements TallyDomain {
	private TallyDao tallyDao;

	public TallyDomainImpl() throws ImplementNotFoundException {
		tallyDao = ClassUtils.getInterfaceImplement(TallyDao.class);
	}

	/**
	 * 获取收支流水账
	 * 
	 * @return
	 * @throws SQLException
	 */
	public List<JournalAccount> getJournalAccountList()
			throws GetFromDBException {
		return this.tallyDao.getJournalAccountList();
	}

	/**
	 * 增加一条收支记录
	 * 
	 * @param journalAccount
	 * @throws SQLException
	 */
	public void insertJournalAccount(JournalAccount journalAccount)
			throws SaveIntoDBException {
		journalAccount.setId(UUID.randomUUID().toString());
		this.tallyDao.insertJournalAccount(journalAccount);
	}

	/**
	 * 修改一条收支记录
	 * 
	 * @param journalAccount
	 * @throws SQLException
	 */
	public void updateJournalAccount(JournalAccount journalAccount)
			throws SaveIntoDBException {
		this.tallyDao.updateJournalAccount(journalAccount);
	}
}
